<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

if (!($reliability_id = $route->getAdminId()))
	goToPage("/admin/reliability");

$errors = array();

if ($route->POST("action") == 'edit')
{
	$clas = UV::readMQ($route->POST("clas"));
	$title = UV::readMQ($route->POST("title"));
	$text = UV::readMQ($route->POST("text"));
	
	if (count($errors) == 0)
	{
		$query = "update `reliability` set `class` = '$clas',`title`='$title',`text`='$text' where `reliability_id` = '$reliability_id' limit 1";
		$update = $db->sendQuery($query);
		if (!$update)
			$errors[] = "Ошибка обновления записи";
	}
}

$reliability = $db->getRow("select * from `reliability` where `reliability_id` = '$reliability_id' limit 1");
if (!$reliability)
	goToPage("/admin/reliability");

loadPage("head.php");
?>
<h1>Редактирование класса страхования</h1><br /><?php
	if (count($errors) > 0)
		echo "<p class='fail'>".implode("<br />",$errors)."<br /><br /></p>";
	elseif ($route->POST("action") == 'edit')
		echo "<p class='success'>Успешно отредактировано<br /><br /></p>";
?>
<form method='POST' id="edit">
	<input type='hidden' name='action' value='edit' />
	<table cellpadding='3' cellspacing='5'>
		<tr>
			<td width='170px'><label for='clas'>Класс</label></td>
			<td width='600px'><input type='text' class='short' id='clas' name='clas' value='<?php echo $reliability['class']; ?>' /></td>
		</tr>
		<tr>
			<td><label for='title'>Заголовок</label></td>
			<td><input type='text' id='title' name='title' value='<?php echo $reliability['title']; ?>' /></td>
		</tr>
		<tr>
			<td><label for='text'>Текст</label></td>
			<td><textarea id='text' name='text'><?php echo $reliability['text']; ?></textarea></td>
		</tr>
		<tr>
			<td colspan='2' align='right'><input type='submit' value='Редактировать' /></td>
		</tr>
	</table>
</form>

<?php loadPage("footer.php"); ?>